import mx.validators.Validator;
			import common.validations.CommonValidations;
			import mx.events.CloseEvent;
			import common.commonFunction;
			import mx.controls.Alert;
			import mx.events.ListEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
[Embed(source="image/error.png")]private var errorIcon:Class;
[Embed(source="image/success.png")]private var successIcon:Class;
[Embed(source="image/reset.png")]private var resetIcon:Class;

			[Bindable]protected var sessionDate:String="";
			 public var url_DNS:String ="";
			[Bindable] public var urlLoadSession:String = "";
			[Bindable] public var xmlDataLoadSession:XML;
			
			[Bindable] public var urlInsertProgramReg:String = "";
			[Bindable] public var xmlInsertionMessage:XML;
			
			
			public function init():void{
			url_DNS = commonFunction.getConstants('url');
    		urlLoadSession = url_DNS+"/programregistration/loadSession.htm";
    		urlInsertProgramReg = url_DNS+"/programregistration/insertProgramReg.htm";
    		getCurrentSession();
			}
			
		public function getString(pass_key:String):String{
			return resourceManager.getString('Constants', pass_key);
		}
		
		
		public function getCurrentSession():void {
       	var params:Object = {};
     		 params["abc"] ="anil";//does not use of params with this send(), it is only used for affect the page contents according dbase
    	     xmlLoadSession.send(params);
        }
        
        public function insertProgramRegistration():void {
       	var params:Object = {};
     		 params["regperiod"] = registrationPeriod.text;//does not use of params with this send(), it is only used for affect the page contents according dbase
    	     params["adddropperiod"] = addDropPeriod.text;
    	     xmlInsertProgramReg.send(params);
        }
        
        private function resultLoadSessionHandler(event:ResultEvent):void{
        xmlDataLoadSession = event.result as XML;
        sessionDate = xmlDataLoadSession.sessionDate;
       }
        private function resultInsertProgramRegHandler(event:ResultEvent):void{
        xmlInsertionMessage = event.result as XML;
        //Alert.show(xmlInsertionMessage);
        if(xmlInsertionMessage.message==1){
         	Alert.show("Total records found = "+xmlInsertionMessage.totalRecords+
       	"\nRecords inserted = "+xmlInsertionMessage.recInserted+
       	"\nRecords inserted in log file = "+xmlInsertionMessage.recInLogs,
       	commonFunction.getConstants('insertMsg'),0,null,null,errorIcon);
       }
       else if(xmlInsertionMessage.message==0){
       	Alert.show("Total records found = "+xmlInsertionMessage.totalRecords+
       	"\nRecords inserted = "+xmlInsertionMessage.recInserted+
       	"\nRecords inserted in log file = "+xmlInsertionMessage.recInLogs,
       	commonFunction.getConstants('success'),0,null,null,successIcon);
       
        }
        else if(xmlInsertionMessage.message==-1){
       	Alert.show(commonFunction.getConstants('insertFailed'),
       	commonFunction.getConstants('fail'),0,null,null,errorIcon);
       }
       }
       
       private function faultLoadSessionHandler(event:FaultEvent):void{
         mx.controls.Alert.show(event.fault.message,commonFunction.getConstants('errorInResult'));
    }
			
			/**
			 * @protected
			 * this method is called to validate the form fields.
			 */
			public function validateForm():Boolean
			{
				var flag:int=0;

				if(Validator.validateAll([registrationPeriodValid, addDropPeriodValid]).length!=0){
					Alert.show(commonFunction.getMessages('validateMessage'));
					flag++;		
				}
				if(Number(registrationPeriod.text)>99){
					registrationPeriod.errorString=">99 is not allowed";
					flag++;
				}
				if(Number(addDropPeriod.text)>99){
					addDropPeriod.errorString=">99 is not allowed";
					flag++;
				}
				
				return (flag>0?false:true);
			}
			
						
			/**
			 * @protected
			 * this method send the Form's data to server side to save.
			 * @param event a mouse event object.
			 */
			protected function saveButtonClickHandler(event:MouseEvent):void
			{
				 if(validateForm())
				 { 
					Alert.show(commonFunction.getMessages('saveConfirmMessage'), '', 3, this, insertRecords);	
				 }  
			}
			
			/**
		 * @protected
		 * this method is called on Alert Box Close Event
		 * this method will inactivate the selected record.
		 * @param event a close event object.
		 */
		protected function insertRecords(event:CloseEvent):void
		{
			if(event.detail == Alert.YES)
			{
				insertProgramRegistration();
			}
		}
			
			/**
			 * @protected
			 * to close the form.
			 * @param event a mouse event object.
			 */
			protected function cancelButtonClickHandler(event:MouseEvent):void
			{
				this.removeAllChildren();
				document.visible=false;
			}					